package setup;

import java.awt.Color;
import java.util.Random;
import java.util.ResourceBundle;

import adapter.Adapter;
import desktop_fields.*;
import desktop_resources.GUI;
import field.Field;
import field.Ownable;

public class Gameboard {

	private desktop_fields.Field[] guiFields;

	/**
	 * Shuffler pegepinde i et array af Fields
	 * @param shuffleFields Arrayet af pegepinde der skal shuffles
	 */
	public void shuffle(Field[] shuffleFields){
		Random rnd = new Random();
		Field[] tempField = new Field[shuffleFields.length-1];
		System.arraycopy(shuffleFields, 1, tempField, 0, tempField.length);
		for (int i = tempField.length - 1; i > 0; i--){
			int index = rnd.nextInt(i + 1);
			// Simple swap
			Field a = tempField[index];
			tempField[index] = tempField[i];
			tempField[i] = a;
		}		
		// kopierer tempField over i field startende fra plads nummer 1.
		System.arraycopy(tempField, 0, shuffleFields, 1, tempField.length);
	}

	/**
	 * Opretter array af GUI felter så rækkefølgen matcher fields-rækkefølge hvis det er shufflet.
	 */
	public void createGuiFields(Field[] fields){
		Adapter adapt = new Adapter();
		ResourceBundle msg = adapt.getBundle();
		
		Color black = new Color(0,0,0);
		guiFields = new desktop_fields.Field[40];

		for (int n = 0; n < fields.length; n++){
			switch (fields[n].getFieldNumber()){
			case 1 : {
				Integer cnq = ((field.Refuge) fields[n]).getConsequence();
				desktop_fields.Start f = new Start.Builder()
				.setTitle(fields[n].getTitle())
				.setSubText(fields[n].getSubtitle() + cnq)
				.setDescription(fields[n].getDesc() + cnq)
				.setFgColor(black)
				.setBgColor(new Color(255,0,0))
				.build();
				guiFields[n] = f;
			}
			break;
			case 2 :{
				Integer price = ((Ownable) fields[n]).getPrice(); //Gemmer int som Integer så der kan bruges toString på værdien

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(75,155,225))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 3 :{
				desktop_fields.Chance f = new Chance.Builder()
				.setBgColor(new Color(255,125,0))
				.build();
				guiFields[n] = f;
			}
			break;
			case 4 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(75,155,225))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 5 :{			
				int tax = ((field.Tax) fields[n]).getTax();
				desktop_fields.Tax f = new Tax.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getSubtitle() + tax)
				.setSubText(fields[n].getSubtitle() + tax)
				.setFgColor(black)
				.setBgColor(new Color(150,150,150))
				.build();
				guiFields[n] = f;
			}
			break;
			case 6 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 
				
				desktop_fields.Shipping f = new Shipping.Builder()
				.setPicture("default")
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,255,255))
				.build();
				guiFields[n] = f;
			}
			break;
			case 7 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,135,120))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 8 :{
				desktop_fields.Chance f = new Chance.Builder()
				.setBgColor(new Color(255,125,0))
				.build();
				guiFields[n] = f;
			}
			break;
			case 9 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,135,120))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 10 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,135,120))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 11 :{
				desktop_fields.Jail f = new Jail.Builder()
				.setPicture("default")
				.setTitle(fields[n].getTitle())
				.setSubText(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.build();
				guiFields[n] = f;
			}
			break;
			case 12 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(230,230,0))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 13 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Brewery f = new Brewery.Builder()
				.setPicture("default")
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(50,170,50))
				.setRent(msg.getString("Brewery_Rent"))
				.build();
				guiFields[n] = f;
			}
			break;
			case 14 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(230,230,0))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 15 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(230,230,0))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 16 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 
				desktop_fields.Shipping f = new Shipping.Builder()
				.setPicture("default")
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,255,255))
				.build();
				guiFields[n] = f;
			}
			break;
			case 17 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(210,210,210))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 18 :{
				desktop_fields.Chance f = new Chance.Builder()
				.setBgColor(new Color(255,125,0))
				.build();
				guiFields[n] = f;
			}
			break;
			case 19 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(210,210,210))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 20 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(210,210,210))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 21 : {
				desktop_fields.Refuge f = new Refuge.Builder()
				.setTitle(fields[n].getTitle())
				.setSubText(fields[n].getSubtitle())
				.setDescription(fields[n].getDesc())
				.setFgColor(black)
				.setBgColor(new Color(255,255,255))
				.build();
				guiFields[n] = f;
			}
			break;
			case 22 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,50,50))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 23 :{
				desktop_fields.Chance f = new Chance.Builder()
				.setBgColor(new Color(255,125,0))
				.build();
				guiFields[n] = f;
			}
			break;
			case 24 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,50,50))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 25 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,50,50))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 26 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 
				desktop_fields.Shipping f = new Shipping.Builder()
				.setPicture("default")
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,255,225))
				.build();
				guiFields[n] = f;
			}
			break;
			case 27 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(0,230,230))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 28 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(0,230,230))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 29 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Brewery f = new Brewery.Builder()
				.setPicture("default")
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(50,170,50))
				.setRent(msg.getString("Brewery_Rent"))
				.build();
				guiFields[n] = f;
			}
			break;
			case 30 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(0,230,230))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 31 : {
				desktop_fields.Jail f = new Jail.Builder()
				.setPicture("default")
				.setTitle(fields[n].getTitle())
				.setSubText(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.build();
				guiFields[n] = f;
			}
			break;
			case 32 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(0,51, 214))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 33 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(0,51, 214))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 34 :{
				desktop_fields.Chance f = new Chance.Builder()
				.setBgColor(new Color(255,125,0))
				.build();
				guiFields[n] = f;
			}
			break;
			case 35 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(0,51, 214))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 36 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 
				desktop_fields.Shipping f = new Shipping.Builder()
				.setPicture("default")
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(255,255,225))
				.build();
				guiFields[n] = f;
			}
			break;
			case 37 :{
				desktop_fields.Chance f = new Chance.Builder()
				.setBgColor(new Color(255,125,0))
				.build();
				guiFields[n] = f;
			}
			break;
			case 38 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(142,0,189))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			case 39 :{
				int tax = ((field.Tax) fields[n]).getTax();
				desktop_fields.Tax f = new Tax.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getSubtitle() + tax)
				.setSubText(fields[n].getSubtitle() + tax)
				.setFgColor(black)
				.setBgColor(new Color(150,150,150))
				.build();
				guiFields[n] = f;
			}
			break;
			case 40 :{
				Integer price = ((Ownable) fields[n]).getPrice(); 

				desktop_fields.Street f = new Street.Builder()
				.setTitle(fields[n].getTitle())
				.setDescription(fields[n].getDesc())
				.setSubText(fields[n].getSubtitle() + price)
				.setFgColor(black)
				.setBgColor(new Color(142,0,189))
				.setRent(price.toString())
				.build();
				guiFields[n] = f;
			}
			break;
			}
		}

		GUI.create(guiFields); // Opretter GUI spillepladen vha. arrayet. GUI'en starter først når den kaldes herefter.
	}
	
	public desktop_fields.Field[] getGuiFields(){
		return guiFields;
	}









}
